﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Validity.Rules;
using Validity.Rules.Decorators;

namespace Validity.Test.Rules.Decorators
{
  [TestClass]
  public class CustomMessageRuleDecoratorTest
  {
    private readonly Mock<IRule<ObjectStub, Object>> _baseRule;
    private readonly ObjectStub _objectStub = new ObjectStub();

    public CustomMessageRuleDecoratorTest()
    {
      _baseRule = new Mock<IRule<ObjectStub, Object>>(MockBehavior.Strict);
    }

    [TestMethod]
    public void TestGetRuleViolationReturnsDefaultOnNullMessageFactoryResult()
    {
      var rule = new CustomMessageRuleDecorator<ObjectStub, Object>(_baseRule.Object, (obj, val) => null);

      Assert.AreEqual("Value is invalid", rule.GetRuleViolation(new ObjectStub(), new Object()));
    }

    [TestMethod]
    public void TestGetRuleViolationReturnsNonNullMessageFactoryResult()
    {
      var rule = new CustomMessageRuleDecorator<ObjectStub, Object>(_baseRule.Object, (obj, val) => "My Custom Message");

      Assert.AreEqual("My Custom Message", rule.GetRuleViolation(new ObjectStub(), new Object()));
    }
  }
}
